#include"file.h"
class show{
public:
    void menu(){
        cout<<"************************************"<<endl;  
        cout<<"*****Welcome to staffing system*****"<<endl; 
        cout<<"*****  1.show staff infomation  ****"<<endl; 
        cout<<"*****  2.add  one  new   staff  ****"<<endl; 
        cout<<"*****  3.remove one old staff   ****"<<endl; 
        cout<<"*****  4.find staff  with  key  ****"<<endl; 
        cout<<"*****  5.amend the information  ****"<<endl; 
        cout<<"*****  6.static info with ket   ****"<<endl;
        cout<<"*****  0.press  '0'  to   exit  ****"<<endl; 
        cout<<"************************************"<<endl;  
        cout<<"enter your choice:  ";
    }
    void print(list<employee> *l1){
        for(list<employee>::iterator i = l1->begin();i!=l1->end();++i)
            i.print();
        cout<<"there are  "<<l1->num<<"  staffs in your company "<<endl;
    }
    void add(list<employee> *l ){
        cout<<"add infomation in file or input ?   file : 1    input : 2"<<endl;
        char way;
        cin>>way;
        if(way == '1'){
            cout<<"enter your filename :  ";
            string file;
            cin>>file;
            file += ".txt";
            my_file f;
            list<employee> lt;
            lt = f.myread(file);
            for(list<employee>::iterator i = lt.begin(); i !=lt.end();++i){
                l->push_back(i.p->data);
            }
            auto fn = [](string s,string s1)->bool{return s > s1; };
            l->sort(fn);
            print(&lt);
        }else {
            int n = 0;
            cout<<"how many staff you want to add: ";
            cin>>n;
            for(int i = 0;i<n;i++){
                employee *e = new employee();
                cout<<"enter your eid : ";
                cin>>e->eid;
                cout<<"enter your name : ";
                cin>>e->name;
                cout<<"enter your gender : ";
                cin>>e->gender;
                cout<<"enter your dob : ";
                cin>>e->dob;
                cout<<"enter your doe : ";
                cin>>e->doe;
                cout<<"enter your unit : ";
                cin>>e->unit;
                cout<<"enter your title name : 0.manager,1.hr specialist,2.finical officer , 3.saler,4.executive"<<endl;
                int num;
                string name;
                cin>>num;
                switch(num){
                    case 0:name = "Manager";break;
                    case 1:name = "HR_spec";break;
                    case 2:name = "Finical";break;
                    case 3:name = "Saler";break;
                    case 4:name = "Execut";break;                    
                }
                title t(name,num);
                e->my_title = t;
                e->showinfo();
                l->push_back(e);
                auto fn = [](string s,string s1)->bool{return s > s1; };
                l->sort(fn);
            }
        }
    }
    void remove(list<employee> *l){
        print(l);
        cout<<"how many you want to remove : ";
        int num;
        cin>>num;
        for(int i = 0;i<num;i++){
            cout<<"which one you want to remove : ";
            int x;
            cin>>x;
            l->remove(x);
            print(l);
        }
    }    
    void search(list<employee> *l1){
        auto fn = [](auto a,auto b)->bool{return a == b ;};
        list<employee> *la  = new list<employee>();
        std::cout<<"enter the range: "<<std::endl;
        int star,end;
        std::cout<<"start : ";
        std::cin>>star;
        std::cout<<"end :   ";
        std::cin>>end;
        *la = l1->find_range((*l1)[star-1],(*l1)[end],fn);
        print(la);
    }
    void modify(list<employee> *l){
        print(l);
        int choice;
        std::cout<<"1.modify staff info.   2.modify titlename"<<std::endl;
        std::cin>>choice;
        if(choice == 1){
            list<employee>::iterator i;
            std::cout<<"which one you want modify : enter eid  : ";
            string the_eid;
            std::cin>>the_eid;
            for(i = l->begin(); i!=l->end();++i){
                if(i.p->data->eid == the_eid)
                    break;
            }
            if(i.p == nullptr){
                std::cout<<"wrong eid ,press enter to continue.";
                return ;
            }
            std::cout<<"enter new name";
            std::cin>>i.p->data->name;
            std::cout<<"enter new gender";
            std::cin>>i.p->data->gender;
            std::cout<<"enter new dob";
            std::cin>>i.p->data->dob;
            std::cout<<"enter new doe";
            std::cin>>i.p->data->doe;
            std::cout<<"enter new unit";
            std::cin>>i.p->data->unit;
        }else{
            cout<<"which postion's salary will change : 0.manager  1.hr specialist  2.finical officer  3.saler  4.executive"<<endl;
            int index;
            cin>>index;
            l->begin().p->data->change_pay(index);
        }
    }
    void look_for(list<employee> *l){
        std::cout<<"what side you want to look for : 1.gender  2.unit  3.title  : ";
        int choice;
        std::cin>>choice;
        if(choice == 1){
            int sum = 0;
            std::cout<<"enter aim gender : ";
            std::string gender;
            std::cin>>gender; 
            for(list<employee>::iterator i = l->begin();i!=l->end();++i){
                if(gender == i.p->data->gender){
                    i.print();
                    sum++;
                }
            }
            if(sum == 0)
                std::cout<<"can't find that people.";
            std::cout<<"total : "<<sum<<std::endl;
        }else if(choice ==2){
            int sum = 0;
            std::cout<<"enter aim unit : ";
            std::string unit;
            std::cin>>unit; 
            for(list<employee>::iterator i = l->begin();i!=l->end();++i){
                if(unit == i.p->data->unit){
                    i.print();
                    sum++;
                }
            }
            if(sum == 0)
                std::cout<<"can't find that people.";
            std::cout<<"total : "<<sum<<std::endl;
        }else if(choice == 3){
            int sum = 0;
            std::cout<<"enter aim title : ";
            std::string title;
            std::cin>>title; 
            for(list<employee>::iterator i = l->begin();i!=l->end();++i){
                if(title == i.p->data->my_title.title_name){
                    i.print();
                    sum++;
                }
            }
            if(sum == 0)
                std::cout<<"can't find that people.";
            std::cout<<"total : "<<sum<<std::endl;
        }else{
            std::cout<<"wrong input.";
            return;
        }
    }
};